﻿using Common;
using Common.CustomException;
using Common.ParameterLocator;
using NUnit.Framework;

namespace SpecFlowTfsConnector.Test
{
    [TestFixture]
    public class TfsConnectorTest : UnitTestInitialization
    {
        [SetUp]
        public new void Initialize()
        {
            base.Initialize();
            ServiceParameter.Instance.Parameter.TfsServerUrl = TestResource.TfsServerUrl;
        }

        [Test]
        public void CanConnectTfsServer()
        {
            Assert.That(new TfsConnector(), Is.Not.Null);
        }

        [Test]
        public void CanFailToConnectTfsServer()
        {
            ServiceParameter.Instance.Parameter.TfsServerUrl ="http://my-pc:8081/tfs";
            Assert.Throws(Is.TypeOf<TfsException>().And.Message.EqualTo(Error.BadTfsServerUrl),
                          () => new TfsConnector());
        }

        [Test]
        public void CanFailToConnectTfsServerWithoutServerParameter()
        {
            ServiceParameter.Instance.Parameter.TfsServerUrl = string.Empty;
            Assert.Throws(Is.TypeOf<TfsException>().And.Message.EqualTo(Error.TfsServerUrlIsNotProvided),
                          () => new TfsConnector());
        }

        [Test]
        public void CantQueryOnTfsServerWithoutGoodCredential()
        {
            Assert.Throws(
                Is.TypeOf<TfsException>().And.Message.EqualTo(Error.FailToConnectToTfsServer),
                () =>
                    {
                        ServiceParameter.Instance.Parameter.TfsUserNameConnexion = "Morgan";
                        ServiceParameter.Instance.Parameter.TfsPasswordConnexion = "xxxx";
                        new TfsConnector();
                    });
        }
    }
}